<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>烟花</title>
  <style media="screen">
    * {
      margin: 0;
      padding: 0;
    }

    #box {
      width: 800px;
      height: 600px;
      position: relative;
      margin: 100px auto;
      background: #000000;
      border: 2px solid red;
      overflow: hidden;
    }

    .ball {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      position: absolute;
      bottom: 0;
    }
  </style>
</head>

<body>
  <div id="box"></div>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script>
    // 构造函数
    function Fire() {
      this.box = document.querySelector('#box')
      this.bindEvent()
    }

    Fire.prototype.bindEvent = function () {
      var self = this
      // 给box绑定事件
      // 主体创建烟花 运动到目标点
      self.box.onclick = function (e) {
        var e = e || event
        var FireWork = self.createFireWork()
        FireWork.style.left = e.offsetX + 'px'
        // 运动
        // 运动结束后回调函数
        $(FireWork).animate({
          top: e.offsetY
        }, 800, function () {
          // 删除烟花
          FireWork.remove()

        })
      }
    }

    Fire.prototype.createFireWork = function () {
      // 创建一个div
      // 把这个div放在页面中
      var div = document.createElement('div')
      div.className = 'ball'
      // 给div设置随机颜色
      div.style.backgroundColor = '#' + Math.round(parseInt('ffffff', 16) * Math.random()).toString(16).padStart(6, '0')
      this.box.appendChild(div)
      return div
    }

    Fire.prototype.boom = function () {

    }


    var fw = new Fire()

  </script>
</body>

</html>